/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servidor.Controlador;

import BaseDatos.FachadaBBDD;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * This class creates a Thread for delete users to the database
 * @author isabel
 * @author Jorge Perez
 */
public class DeleteUserTask extends Thread implements OcaTask {
   
    private Socket socket;
    private BufferedReader read;
    private PrintWriter write;
    
    public DeleteUserTask(Socket socket, BufferedReader read, PrintWriter write) {
        this.write = write;
        this.socket = socket;
        this.read = read;
    }
   
@Override
    public void executeTask() {
        this.start();
    }
    public void run(){
        
        int idUser = -1;
        String idPlayer = null;
        try {
            idPlayer = read.readLine();

        } catch (IOException ex) {
            System.out.println("Problemas al recibir la id");
            
        }
        try {
            idUser = Integer.parseInt(idPlayer);
        } catch (NumberFormatException ex) {
            System.out.println("La id del jugador recibida no es un numero entero");
        }

        boolean isCorrect = false;
        isCorrect = FachadaBBDD.get_instance().delete_user(idUser);
        write.println(isCorrect);

        new TrashTask(socket, read, write);
    }
   
}
